package cn.coisini.controller.v1;

import cn.coisini.api.admin.AsyncLoginLogControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import cn.coisini.model.common.log.service.AsyncLoginLogService;
import cn.coisini.model.pojo.AsyncLoginLog;
import cn.coisini.model.vo.AsyncLoginLogQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 登录日志
 */
@RestController
@RequiredArgsConstructor
public class AsyncLoginLogController implements AsyncLoginLogControllerApi {

    private final AsyncLoginLogService loginLogService;

    // 分页查询登录日志
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Page<AsyncLoginLog>> pagingQuery(AsyncLoginLogQueryVo asyncLoginLogQueryVo) {
        return loginLogService.pagingQuery(asyncLoginLogQueryVo);
    }

    // 根据id查询登录日志
    @Override
    public Result<AsyncLoginLog> getLoginLog(String id) {
        return loginLogService.get(id);
    }

    // 删除登录日志
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "登录日志管理",businessType = BusinessType.DELETE)
    public Result<ResultEnum> removeLoginLogById(String id) {
        return loginLogService.removeLoginLogById(id);
    }

    // 批量删除登录日志
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "登录日志管理",businessType = BusinessType.BATCH_REMOVE)
    public Result<ResultEnum> batchRemove(List<String> ids) {
        return loginLogService.batchRemove(ids);
    }
}
